package com.itlong.cloud.smartcard.resource;

import com.itlong.cloud.POJO.DTO.smartcard.SmartCardGetAppUserInfoDTO;
import com.itlong.cloud.POJO.DTO.smartcard.SmartCardSyncDataPullUserBasisInfoDTO;
import com.itlong.cloud.POJO.PO.AppUserInfoPO;
import com.itlong.cloud.POJO.VO.property.AppUserGetDeviceAuthVO;
import com.itlong.cloud.smartcard.service.ISmartCardUserInfoService;
import com.itlong.cloud.user.smartcard.ISmartCardUserInfoServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SmartCardUserInfoServiceResource implements ISmartCardUserInfoServiceClient{

    @Autowired
    ISmartCardUserInfoService iSmartCardUserInfoService;

    /**
     * <desc>
     * 保存或更新住户信息以及住户项目信息
     * <desc/>
     *
     * @param smartCardSyncDataPullUserBasisInfoDTO 住户信息传输对象
     * @param projectId                             项目Id
     * @param isSmartCommunity                      是否使用云对讲： 0-否，1-是
     * @return
     * @author zhangs
     * @createDate 2017-11-20
     */
    @Override
    @RequestMapping(path = "smartCard/syncData/saveOrUpdateSmartCardUserBasisInfo", method = RequestMethod.POST)
    public void saveOrUpdateSmartCardUserBasisInfo(@RequestBody  SmartCardSyncDataPullUserBasisInfoDTO smartCardSyncDataPullUserBasisInfoDTO,
                                                   @RequestParam("projectId")String projectId,
                                                   @RequestParam("isSmartCommunity")Integer isSmartCommunity) throws Exception {
        iSmartCardUserInfoService.saveOrUpdateSmartCardUserBasisInfo(smartCardSyncDataPullUserBasisInfoDTO,projectId,isSmartCommunity);

    }

    /**
     * <desc>
     * 根据住户手机号获取住户信息
     * <desc/>
     *
     * @param getAppUserInfoDTO 查询条件
     * @return AppUserInfoPO 住户信息
     * @author zhangs
     * @createDate 2017/11/20
     */
    @Override
    @RequestMapping(path = "smartCard/syncData/getSmartCardAppUserInfo", method = RequestMethod.POST)
    public AppUserInfoPO getSmartCardAppUserInfo(@RequestBody SmartCardGetAppUserInfoDTO getAppUserInfoDTO) throws Exception {
        return iSmartCardUserInfoService.getSmartCardAppUserInfo(getAppUserInfoDTO);
    }

    /**
     * <desc>
     * 与旺龙一卡通对接-处理住户设备权限信息。
     * 一卡通push住户设备权限信息时住户信息为空，先存储住户信息在使用RabbitMQ处理住户设备权限信息
     * <desc/>
     *
     * @param phoneNum                住户手机号
     * @param email  住户邮箱
     * @param projectId               项目Id
     * @param isSmartCommunity        是否使用云对讲： 0-否，1-是
     * @param appUserGetDeviceAuthVOS 住户设备权限数据信息
     * @return
     * @author zhangs
     * @createDate 2017/11/20
     */
    @Override
    @RequestMapping(path = "smartCard/syncData/handleSmartCardPushDeviceAuth", method = RequestMethod.POST)
    public void handleSmartCardPushDeviceAuth(@RequestParam("phoneNum")String phoneNum,
                                              @RequestParam("email") String email,
                                              @RequestParam("projectId")String projectId,
                                              @RequestParam("isSmartCommunity")Integer isSmartCommunity,
                                              @RequestBody  List<AppUserGetDeviceAuthVO> appUserGetDeviceAuthVOS) throws Exception {
         iSmartCardUserInfoService.handleSmartCardPushDeviceAuth(phoneNum,email,projectId,isSmartCommunity,appUserGetDeviceAuthVOS);
    }

    /**
     * <desc>
     *      C#端管理中心登陆验证（工程人员）。
     * <desc/>
     *
     * @param projectId 项目编号
     * @param userName 账号
     * @param password 密码
     * @return
     * @author Juguang.S
     * @createDate 2019-03-18
     */
    @Override
    @RequestMapping(path = "/smartCard/engineerLoginVerifyForCFace",method = RequestMethod.POST)
    public Map<String,String> engineerLoginVerifyForCFace(@RequestParam("projectId") String projectId,
                                                   @RequestParam("userName") String userName,
                                                   @RequestParam("password") String password) throws Exception {
        return iSmartCardUserInfoService.engineerLoginVerifyForCFace(projectId,userName,password);
    }

    /**
     * <desc>
     *      从缓存中获取token信息
     * </desc>
     *
     * @param token 用户token
     * @return
     * @author Juguang.S
     * @createDate 2019/03/18
     */
    @RequestMapping(path = "/smartCard/retrieve")
    @Override
    public String retrieve(@RequestParam("token") String token) {
        return iSmartCardUserInfoService.retrieve(token);
    }

    /**
     * <desc>
     *      获取用户信息
     * </desc>
     *
     * @param uid
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2019/11/18
     */
    @RequestMapping(path = "/smartCard/getUserIdByUid")
    @Override
    public String getUserIdByUid(@RequestParam("uid") String uid,@RequestParam("projectId") String projectId){
        return iSmartCardUserInfoService.getUserIdByUid(uid,projectId);
    }

    /**
     * <desc>
     *      查询通行记录
     * </desc>
     *
     * @param uid
     * @param projectId
     * @param passTime
     * @return
     * @author Jiaqi.X
     * @createDate 2019/11/18
     */
    @RequestMapping(path = "/smartCard/getPassIdByQrcodeInfo")
    public String getPassIdByQrcodeInfo(@RequestParam("uid") String uid,@RequestParam("projectId") String projectId,@RequestParam("passTime") String passTime) {
        return iSmartCardUserInfoService.getPassIdByQrcodeInfo(uid, projectId, passTime);
    }

    /**
     * <desc>
     *      人脸下发失败回调
     * <desc/>
     *
     * @param projectId 项目编号
     * @param faceFailDesc  下发失败原因描述(中文)
     * @param userId  人脸识别后的faceId
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2019/11/12
     */
    @Override
    @RequestMapping(path = "/smartCard/faceFailCallback",method = RequestMethod.POST)
    public void faceFailCallback(@RequestParam("projectId") String projectId,
                                 @RequestParam("faceFailDesc") String faceFailDesc,
                                 @RequestParam("userId") String userId) throws Exception {
        iSmartCardUserInfoService.engineerLoginVerifyForCFace(projectId,faceFailDesc,userId);
    }



    /**
     * <desc>
     *      更新二维码信息
     * </desc>
     *
     * @param visitorId 访客id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/5/31
     */
    @RequestMapping("/smartCard/qrCode/update")
    @Override
    public String updateQRCode(@RequestParam("visitorId") String visitorId) throws Exception {
        return iSmartCardUserInfoService.updateQRCode(visitorId);
    }


}
